#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
using namespace std;


struct Student {
    std::string name;
    int score;
};

void task1() {
    // TODO
    std::vector<int> numbers = {3, 5, 2, 8, 1, 10};

    vector<int> doubled;
    transform(numbers.begin(), numbers.end(), back_inserter(doubled), [](int x) { return x * 2; });
    cout<<"Doubled vector: ";
    for (int i=0;i<doubled.size();i++) {
        cout<<doubled[i]<<" ";
    }
    cout<<endl;

    vector<int> filtered;
    copy_if(numbers.begin(), numbers.end(), back_inserter(filtered), [](int x) {return x>5;});
    cout<<"Filtered vector (> 5): ";
    for (int i=0;i<filtered.size();i++) {
        cout<<filtered[i]<<" ";
    }
    cout<<endl;

    sort(numbers.begin(), numbers.end(),
        [](int x,int y){
            return abs(x-5)<abs(y-5);
        }
    );
    cout<<"Sorted by absolute difference from 5: ";
    for (int i=0;i<numbers.size();i++) {
        cout<<numbers[i]<<" ";
    }
    cout<<endl;
}

void task2() {
    // TODO
    std::vector<Student> students = {{"Alice", 85}, {"Bob", 72}, {"Charlie", 90}};
    sort(students.begin(), students.end(),
        [](Student x, Student y){
            return x.score>y.score;
        }
    );
    cout<<"Students sorted by score (descending):"<<endl;
    for (int i=0;i<students.size();i++) {
        cout<<students[i].name<<": "<<students[i].score<<endl;
    }
    cout<<endl;

    cout<<"Students with score > 80:"<<endl;
    for_each(students.begin(), students.end(),
        [](Student x){
            if (x.score>80) {
                cout<<x.name<<endl;
            }
        }
    );
}

void task3() {
    // TODO
    std::vector<int> numbers = {3, 5, 2, 8, 1, 10};
    int result=accumulate(numbers.begin(), numbers.end(),1,
        [](int x, int y){
            if (y%2==0) return x*y;
            else return x;
        }
    );
    cout<<"Product of even numbers: "<<result<<endl;
}

int main() {
    cout << "Task 1 Solution:" << std::endl;
    task1();

    cout << "\nTask 2 Solution:" << std::endl;
    task2();

    cout << "\nTask 3 Solution:" << std::endl;
    task3();

    return 0;
}